using System.Collections.Generic;
using UnityEngine;

namespace RecommendedProduct
{
	public class SelectHandlerNext : SelectHandlerAbstract
	{
		public override List<Product> GetProduct(List<Product> products)
		{
			List<Product> list = new List<Product>();
			if (products.Count == 0)
			{
				return list;
			}
			List<Product> list2 = new List<Product>();
			List<Product> list3 = new List<Product>();
			foreach (Product product in products)
			{
				if (product.Purchased)
				{
					list.Clear();
					list2.AddRange(list3);
					list3.Clear();
				}
				if (MarketController.CanBuyProduct(product))
				{
					list.Add(product);
					list3.Add(product);
					if (list.Count >= _count)
					{
						return list;
					}
				}
			}
			if (list.Count < _count && list2.Count > 0)
			{
				int num = _count - list.Count;
				List<Product> collection = new List<Product>(list);
				list.Clear();
				for (int i = Mathf.Max(0, list2.Count - num); i < list2.Count; i++)
				{
					list.Add(list2[i]);
				}
				list.AddRange(collection);
			}
			return list;
		}
	}
}
